package com.bjshiwei.zhengu.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bjshiwei.zhengu.R;

/**
 * 作者：Administrator on 2017/2/13 0013 16:39
 * 邮箱：sanjins@126.com
 */


public class SquareView extends RelativeLayout{

    private TextView mTextViewTop;
    private TextView mTextViewCenter;
    private TextView mTextViewBottom;

    public SquareView(Context context) {
        this(context,null);
    }

    public SquareView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context,attrs);
    }

    public SquareView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context,attrs);
    }


    private void init(Context context, AttributeSet attrs) {
        View inflate = inflate(context, R.layout.custom_home_square, this);
        mTextViewTop = (TextView) inflate.findViewById(R.id.tv_home_custom1);
        mTextViewCenter = (TextView) inflate.findViewById(R.id.tv_home_custom2);
        mTextViewBottom = (TextView) inflate.findViewById(R.id.tv_home_custom3);

        TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.SquareViewAttr);
        String textTop = (String) ta.getText(R.styleable.SquareViewAttr_text_top);
        if(!TextUtils.isEmpty(textTop)) {
            mTextViewTop.setText(textTop);
        }

        String textCenter = (String) ta.getText(R.styleable.SquareViewAttr_text_center);
        if(!TextUtils.isEmpty(textCenter)) {
            mTextViewCenter.setText(textCenter);
        }

        String textBottom = (String) ta.getText(R.styleable.SquareViewAttr_text_bottom);
        if(!TextUtils.isEmpty(textBottom)) {
            mTextViewBottom.setText(textBottom);
        }

        ta.recycle();
    }

    public void setmTextViewTop(String text){
        mTextViewTop.setText(text);
    }

    public void setmTextViewCenter(String center){
        mTextViewCenter.setText(center);
    }

    public void setmTextViewBottom(String bottom){
        mTextViewBottom.setText(bottom);
    }
}
